﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Win32;

namespace SnShared
{
    public class Config
    {
        private static object GetVal(String val)
        {
            RegistryKey config = Registry.LocalMachine.OpenSubKey("Software\\JWSecure\\CDM");

            if (config == null)
            {
                throw new Exception("Couldn't open JWSecure registry key.");
            }

            object o = config.GetValue(val);
            if (o == null)
            {
                throw new Exception("Couldn't open value " + val);
            }

            return o;
        }

        private static String GetString(String val)
        {
            object o = GetVal(val);
            return (string)o;
        }
        
        public static String GetServiceUrl()
        {
            return GetString("ServiceUri");
        }

        public static string GetConnectionString()
        {
            return GetString( "ConnectionString" );
        }

        internal static String GetTemplateName()
        {
            return GetString("MachineTemplate");
        }
    }
}
